# 202. 快乐数
def isHappy(n: int) -> bool:
    num_set = set()
    flag = n
    while flag != 1:
        # 出现循环了
        if flag in num_set:
            break
        # 放到 set 中
        num_set.add(flag)
        temp = 0
        while flag != 0:
            word = flag % 10
            temp += word ** 2
            flag = int(flag / 10)
        flag = temp
    return flag == 1


n_1 = 19
result = isHappy(n_1)
print(f"result:{result}")

n_1 = 2
result = isHappy(n_1)
print(f"result:{result}")

n_1 = 1
result = isHappy(n_1)
print(f"result:{result}")

n_1 = 7
result = isHappy(n_1)
print(f"result:{result}")
